package com.txh.blog.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * rabbitMQ配置类
 */
@Configuration
public class MqConfig {
    /**
     * 使用topic模式交换机，根据路由键匹配
     */

    private final String MESSAGE = "topic.message";

    private final String MESSAGES = "topic.messages";

    /**
     * 消息队列名称
     * @return
     */
    @Bean
    public Queue queueMessage(){
        return new Queue("topic.message");
    }
    /*@Bean
    public Queue queueMessages(){
        return new Queue("topic.messages");
    }*/

    /**
     * topic交换机
     * @return
     */
    @Bean
    public TopicExchange exchange(){
        return new TopicExchange("exchange");
    }
    /**
     * 绑定交换机
     */
    @Bean
    public Binding bindingExchangeQueueMessage(Queue queueMessage, TopicExchange exchange){
        return BindingBuilder.bind(queueMessage).to(exchange).with(MESSAGE);
    }

    /*@Bean
    public Binding bindingExchangeQueueMessages(Queue queueMessage,TopicExchange exchange){
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.#");//*匹配一个，#匹配多个
    }*/
}
